home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
2_2.lha
/
2_2
/
lsqrt.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
578b
|
24 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
include <complex.h>
omplex lsqrt(complex z)
double x = real(z);
double y = imag(z);
// convert to polar and take root
// 2 2 1/2
// r = (x + y )
//
// theta = O = arc tan (y / x)
//
// 1/2 1/2
// z = r (cos O/2 + i sin O/2)
double root_r = sqrt(sqrt(x * x +
y * y));
double half_t = atan2(y, x) / 2.0;
return complex(root_r * cos(half_t),
root_r * sin(half_t));